package net.tavion.angelboot.fegin.interceptor;

import net.tavion.angelboot.fegin.logger.AccessLogger;
import net.tavion.angelboot.fegin.logger.ResponseInfo;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

public class FeignClientInterceptor implements MethodInterceptor {
    private AccessLogger accessLogger;

    public FeignClientInterceptor(AccessLogger accessLogger) {
        this.accessLogger = accessLogger;
    }

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
//        String originalMsgId = LemonUtils.getMsgId();

        Object var3;
        try {
//            LemonHolder.getLemonData().setMsgId(IdGenUtils.generateMsgId());
//            LemonContext.getCurrentContext().put(FeignConstants.getFeignInvocationStartTimeContextKey(), Instant.now());
            var3 = invocation.proceed();
        } catch (Exception var8) {
            ResponseInfo<String> responseInfo = ResponseInfo.stringBuilder().uri("uri").duration(20L).appName("APPnAME").loginName("LOGINnAME").token("x-token").result(var8.getMessage()).build();
            this.accessLogger.response(responseInfo);
            throw var8;
        } finally {
//            LemonContext.getCurrentContext().remove(FeignConstants.getFeignInvocationStartTimeContextKey());
//            LemonHolder.getLemonData().setMsgId(originalMsgId);
        }
        ResponseInfo<String> responseInfo = ResponseInfo.stringBuilder().uri("uri").duration(20L).appName("APPnAME").loginName("LOGINnAME").token("x-token").result(var3).build();

        this.accessLogger.response(responseInfo);
        return var3;
    }
}